﻿using EFCoreIdentitySample.Domain.Core;
using EFCoreIdentitySample.Repository.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EFCoreIdentitySample.Repository
{
    public class ApplicationDbContextSeed
    {
        private UserManager<ApplicationUser> _userManager;
        public async System.Threading.Tasks.Task SeedAsync(ApplicationDbContext ctx, IServiceProvider services)
        {
            if (!ctx.Users.Any())
            {
                _userManager = services.GetRequiredService<UserManager<ApplicationUser>>();
                var user = new ApplicationUser()
                {
                    Email = "519564415@qq.com",
                    UserName = "Administrator",
                    NormalizedUserName = "Administrator",
                    NormalizedEmail = "519564415@qq.com"
                };
               await _userManager.CreateAsync(user,"p@ssw0rd");
            }
        }
    }
}
